// 临时的Vue Router模拟实现

// 模拟createRouter函数
export function createRouter(options) {
  // 简单的路由实现
  const router = {
    currentRoute: { path: '/' },
    routes: options.routes,
    push(to) {
      // 简单的路径变化处理
      window.location.hash = to
      this.currentRoute.path = typeof to === 'string' ? to : to.path
      this.notifyListeners()
    },
    replace(to) {
      // 简单的replace实现
      window.location.replace(`#${typeof to === 'string' ? to : to.path}`)
      this.currentRoute.path = typeof to === 'string' ? to : to.path
      this.notifyListeners()
    },
    listeners: [],
    onReady(callback) {
      setTimeout(callback, 0)
    },
    beforeEach(guard) {
      this.beforeGuards.push(guard)
    },
    afterEach(hook) {
      this.afterHooks.push(hook)
    },
    notifyListeners() {
      this.listeners.forEach(listener => listener(this.currentRoute))
    }
  }
  
  // 监听URL变化
  window.addEventListener('hashchange', () => {
    const path = window.location.hash.slice(1) || '/'
    router.currentRoute.path = path
    router.notifyListeners()
  })
  
  return router
}

// 模拟createWebHistory函数
export function createWebHistory() {
  return {}
}

// 模拟Vue Router插件
export const VueRouter = {
  install(app) {
    // 提供全局的$router和$route属性
    app.config.globalProperties.$router = {}
    app.config.globalProperties.$route = { path: '/' }
  }
}

// 导出插件安装函数
export const createRouterMatcher = () => ({});
export const useRouter = () => ({});
export const useRoute = () => ({ path: '/' });
export const RouterView = {
  name: 'RouterView',
  render() {
    // 非常简单的RouterView实现
    // 实际项目中需要根据路由配置渲染对应的组件
    return null
  }
};

export const RouterLink = {
  name: 'RouterLink',
  props: {
    to: {
      type: [String, Object],
      required: true
    },
    href: {
      type: String,
      default: ''
    }
  },
  render() {
    // 简单的RouterLink实现
    return this.$slots.default ? this.$slots.default()[0] : null
  }
};